/////////////////////////////////////////////////////////////////////////////
// Name:        ax_controller_standard.h
// Purpose:     Standard menu controller, using a list control.
// Author:      Julian Smart
// Modified by:
// Created:     2009-03-20
// RCS-ID:
// Copyright:   (c) Julian Smart
// Licence:     New BSD License
/////////////////////////////////////////////////////////////////////////////

#ifndef _AX_CONTROLLER_STANDARD_H_
#define _AX_CONTROLLER_STANDARD_H_

/*
 * Includes
 */

#include "wx/listctrl.h"
#include "ax/ax_menu.h"

// Native wxListCtrl on Mac has a few problems. So for now, explicitly
// use wxGenericListCtrl on Mac.

#ifdef __WXMAC__
#define axUSE_GENERIC_LISTCTRL 1
#else
#define axUSE_GENERIC_LISTCTRL 0
#endif

#if axUSE_GENERIC_LISTCTRL
#include "wx/generic/listctrl.h"
#define AxListCtrlClass wxGenericListCtrl
#else
#define AxListCtrlClass wxListCtrl
#endif

class AxStandardMenuController;
class AxVisualSettings;

/**
    @class AxMenuListCtrl

    Defines a list control to use in conjunction with AxStandardMenuController.

    @category{ax}
 */

#if axUSE_GENERIC_LISTCTRL
class AxMenuListCtrl: public wxGenericListCtrl
#else
class AxMenuListCtrl: public wxListCtrl
#endif
{
    DECLARE_CLASS( AxMenuListCtrl )
    DECLARE_EVENT_TABLE()

public:
// Constructors

    AxMenuListCtrl() { Init(); }

    AxMenuListCtrl(wxWindow* parent, wxWindowID id = wxID_ANY, const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxDefaultSize, long style = wxLC_REPORT);
    ~AxMenuListCtrl();

    void SetController(AxStandardMenuController* controller) { m_controller = controller; }

    bool Create(wxWindow* parent, wxWindowID id = wxID_ANY, const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxDefaultSize, long style = wxLC_REPORT);

    void Init();

    /// Called when the menu must be refreshed
    virtual bool RefreshMenu(AxMenu* menu);

    /// Called when a menu item must be updated
    virtual bool UpdateMenuItem(AxMenu* menu, AxMenuItem* item);

    /// Set the menu item data
    virtual bool SetMenuItemData(wxListItem& info, AxMenuItem* item);

    /// Called when a menu item should be selected
    virtual bool SetMenuSelection(AxMenuItem* menuItem);

    /// Called to get the currently selected menu item
    virtual AxMenuItem* GetMenuSelection() const;

    /// Set selection
    void SetSelection(long sel, bool select);

    /// Get selection
    int GetSelection() const;

    /// Perform any required idle processing
    virtual bool IdleProcessing();

    /// Apply settings to the appearance, in particular the background colour
    virtual bool ApplySettings(int hints, const AxVisualSettings& settings);

    void OnSelect(wxListEvent& event);
    void OnActivate(wxListEvent& event);
    void OnSize(wxSizeEvent& event);
    void OnChar(wxKeyEvent& event);
    // void OnIdle(wxIdleEvent& event);

protected:
    AxStandardMenuController* m_controller;
    AxMenu*                 m_menu;
    int                     m_toActivate;
};

/**
    @class AxStandardMenuController

    The default menu controller class, to use with AxMenuListCtrl and AxContainerCtrl.

    @category{ax}
 */


class AxStandardMenuController: public AxMenuController
{
    DECLARE_CLASS( AxStandardMenuController )

public:
// Constructors

    AxStandardMenuController(AxMenuListCtrl* listCtrl = NULL, wxTextCtrl* textCtrl = NULL)
    { Init(); m_listCtrl = listCtrl; m_textCtrl = textCtrl; }
    ~AxStandardMenuController();

// Operations

    void Init();

    /// Called when the menu must be refreshed - implement for a specific control
    virtual bool RefreshMenu(AxMenu* menu, AxNavigationHint hint);

    /// Called when a menu item should be selected - implement for a specific control
    virtual bool SetMenuSelection(AxMenuItem* menuItem);

    /// Called when a menu item must be updated
    virtual bool UpdateMenuItem(AxMenuItem* item);

    /// Called when the current view title should be changed - implement for a specific title control
    virtual bool SetTitle(const wxString& title);

    /// Called when we need to get the currently selected menu item - implement for a specific control
    virtual AxMenuItem* GetMenuSelection() const;

    /// Called when the menu becomes modal
    virtual bool BeginModal();

    /// Called when the menu stops being modal
    virtual bool EndModal();

    /// Perform idle processing
    virtual bool IdleProcessing();

    /// Called when the menu should get the focus.
    virtual bool SetMenuFocus();

    /// Override to update the appearance when settings change.
    virtual bool UpdateAppearance(int hints);

    AxMenuListCtrl* GetListCtrl() const { return m_listCtrl; }
    wxTextCtrl* GetTextCtrl() const { return m_textCtrl; }

    void SetListCtrl(AxMenuListCtrl* listCtrl) { m_listCtrl = listCtrl; }
    void SetTextCtrl(wxTextCtrl* textCtrl) { m_textCtrl = textCtrl; }
protected:

    AxMenuListCtrl* m_listCtrl;
    wxTextCtrl*     m_textCtrl;
};

#endif
    // _AX_CONTROLLER_STANDARD_H_
